/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fallen.deck.front_end.jCustomTabbed;

import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author MotorolaUTN
 */
public class comboCellRender extends DefaultTableCellRenderer {

    private List objects;
    private JComboBox combo;

    public comboCellRender() {
        objects = new ArrayList();
    }

    public comboCellRender(List objects) {
        this.objects = objects;
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        // Cargar los valores para la fila
        combo = new JComboBox();
        setItems(objects);
        // Color de fuente y fondo para filas seleccionadas y no seleccionadas
        if (isSelected) {
            combo.setForeground(table.getSelectionForeground());
            super.setBackground(table.getSelectionBackground());
        } else {
            combo.setForeground(table.getForeground());
            combo.setBackground(table.getBackground());
        }

        // Select the current value
        combo.setSelectedItem(value);
        return combo;
    }

    public void setItems(List items)
    {
        if (combo != null) {
            combo.removeAllItems();
            for (int i = 0; items.size() > i; i++) {
                combo.addItem(items.get(i));
            }
        }
    }
    
    public Object getSelectedItem() {
        if (combo.getSelectedItem() != null)
            return combo.getSelectedItem();
        else
            return null;
    }
}